# Lindsay Gilmour
# Adam Lusch
# Dan Niceswanger
#
# Computer Graphics Project 1:
# Asteroids!
# A Tribute

SHELL = sh
CC = g++
CFLAGS = -O2 -isystem ./Box2D/Include -g -W -Wall -Wextra -ansi -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith -Winline -Wundef -Wcast-qual -Wshadow -Wconversion -Wwrite-strings -Wno-conversion
LD = $(CC)
LIBS = -lbox2d -lglut -lm
LDFLAGS = -L./Box2D/Source/Gen/float
CFILES = $(wildcard *.cpp)
OBJS = $(CFILES:.cpp=.o)
TARGET = asteroids
BOX2DPATH = ./Box2D/Source/
BOX2DLIB = Gen/float/libbox2d.a
BOX2D = $(BOX2DPATH)$(BOX2DLIB)

all : $(TARGET)

$(TARGET) : $(OBJS) $(BOX2D)
	$(LD) $(LDFLAGS) $^ $(LIBS) -o $@
	
$(BOX2D) : 
	(cd $(BOX2DPATH); make $(BOX2DLIB))

-include $(OBJS:.o=.d)

# Automatic dependency generation from http://theory.uwinnipeg.ca/gnu/make/make_43.html
%.d : %.cpp
	$(SHELL) -ec '$(CC) -MM $(CFLAGS) $< \
		| sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
		[ -s $@ ] || rm -f $@'
	
%.o : %.cpp
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	$(RM) *.o *.d $(TARGET)

